//
//  HMNavigationController.swift
//  WeiBoXR
//
//  Created by acer on 16/9/19.
//  Copyright © 2016年 acer. All rights reserved.
//

import UIKit

class HMNavigationController: UINavigationController , UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()

        self.interactivePopGestureRecognizer?.delegate = self
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if viewControllers.count > 0
        {
            if viewControllers.count == 1
            {
                //获取上一级控制器的title
                let title = viewControllers.first!.title!
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title:title, imageName: "navigationbar_back_withtext", target: self, action: #selector(backBtnClick))
            }
            else{
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(backBtnClick))
            }
            viewController.title = "当前显示的第\(viewControllers.count + 1)级控制器"
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }

    
    func backBtnClick()  {
        
        popViewController(animated: true)
    }
    
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool{
        
        if viewControllers.count == 1 {
            return false
        }
        return true
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
